package thread;

import java.util.Timer;
import java.util.TimerTask;

/*
 * @author zzr
 * @date: 2025/04/06  18:50
 * @description:
 */
public class ThreadDemo40 {
    public static void main(String[] args) throws InterruptedException {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                // 时间到了之后，要执行的代码
                System.out.println("hello timer 3000");
            }
        }, 3000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello timer 2000");
            }
        }, 2000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello timer 1000");
            }
        }, 1000);

        timer.cancel();
        System.out.println("hello main");
        Thread.sleep(5000);
    }
}
